package cn.finder.datatunnel.server.test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Hello world!
 *
 */
public class DTServerPoint 
{
	private static boolean looper=true;
    public static void main(String[] args ) throws IOException
    {
    	ServerSocket  serverSocket=null;
    	
   	 	serverSocket=new ServerSocket(7888);
		 
		 boolean isBound=serverSocket.isBound();
		 if(isBound){
			 System.out.println("====socket listening port:"+serverSocket.getLocalPort());
		 }else{
			 System.out.println("====binding port:"+serverSocket.getLocalPort()+ "failure");
			 return ;
		 }
		 
		 
		 while(looper){
		    	
		    	try {
					 Socket socket=serverSocket.accept();//等待客户端请求
					 
					 InetSocketAddress inetAddress=(InetSocketAddress)socket.getRemoteSocketAddress();
					 System.out.println("==== "+inetAddress.getHostName()+" connected=======");
					 
					 try {
						
						new Thread(new ProcessorRunnable(socket)).start();
						
					} catch (Exception e) {
						System.out.println(e);
					} 
					 
					 
				} catch (NumberFormatException e) {
					 System.out.println(e);
				} catch (IOException e) {
					 System.out.println(e);
				}
		    	finally{
		    		try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						 System.out.println(e);
					}
		    	}
		    	
		    	
	    	}
	    	
		 System.out.println("====socket listening port:"+serverSocket.getLocalPort()+" stopped");
		 
		 
    }
}
